<?
require_once('ri/dataMediator/DataMediator.php');

$errors= array();
$data= new DataMediator($_REQUEST);

// converters and validators
$data->setConverter('date','Date')
	->setErrorMessage('Invalid date entered')
	->setDefault(new DateTime('tomorrow'))
	->setFormat('%d/%m/%Y');
$data->addValidator('date','Required')
	->setErrorMessage('Please enter a date');
$data->addValidator('date','DateRange')
	->setErrorMessage('Date must be before today')
	->setMax(new DateTime('today'));

// check form
if (isset($_REQUEST['submitted'])) {
	// conversion and validation
	if (!($errors= $data->getErrors())) {
		// DateTime object
		$date= $data->getAsDatatype('date');
	}
}

// input mask
?>
<h2>Please enter following fields</h2>

<ul>
<? foreach ($errors as $error) { ?>
	<li><?= $error; ?></li>
<? } ?>
</ul>

<form>
	<span>Date:</span>
	<input type="text" name="date" value="<?= $data->getAsString('date') ?>" />
	<input type="submit" name="submitted" value="Submit" />
</form>
